<?php
	namespace Home\Controller;
	use Think\Controller;

	class BlastController extends Controller {
		public function blast() {
			if (isset($_SESSION['uid'])) {
				// var_dump($_SESSION);
				$_SESSION['url'] = $_SERVER['PHP_SELF'];
				$condition = 1;
				$this->assign('username', $_SESSION['username']);
			}
			else {
				$condition = 0;
			}
			$whichTag = 0;
			$this->assign('whichTag', $whichTag);
			$this->assign('condition', $condition);
			$this->display('blast');
		}

		public function goblast() {
			if (isset($_SESSION['uid'])) {
				// var_dump($_SESSION);
				$_SESSION['url'] = $_SERVER['PHP_SELF'];
				$condition = 1;
				$this->assign('username', $_SESSION['username']);
			}
			else {
				$condition = 0;
			}
			$whichTag = 2;
			$this->assign('whichTag', $whichTag);
			$this->assign('condition', $condition);
			$this->display();
		}

		public function getBlast() {
			if (I('post.sequence')){
				// var_dump($_POST);
				$sequence = trim($_POST['sequence']);
				$database = trim(I('post.database'));
				$evalue = trim(I('post.evalue'));
				$wordsize = trim(I('post.wordsize'));
				$max_target_sequences = trim(I('post.max_target_sequences'));

				// var_dump($sequence);
				// var_dump($database);
				// var_dump($evalue);
				// var_dump($wordsize);
				// var_dump($max_target_sequences);
				
				$sequence = str_replace("\n", "EE", $sequence);
				
				// var_dump('python D:/wamp64/www/primer/public/python/blast.py -seq "' . $sequence .'" -evalue ' . $evalue . ' -db "' . $database . '"');

				$output = shell_exec('python D:/wamp64/www/primer/public/python/blast.py -seq "' . $sequence .'" -evalue ' . $evalue .' -db ' . $database. " -wordsize " . $wordsize . " -maxtargetseq " . $max_target_sequences);
				// var_dump($output);

				$array = explode(',', $output);
				foreach ($array as $value) {
					#echo "\n";
					echo $value;
					echo "<br>";
				}
			}
		}

		public function getPrimer() {
			if (I('post.time')) {
				$search = M('search');
				$result = $search->select();
				// var_dump($result);
				// if ($result) {
				// 	$html = '<h1>test</h1>';
				// }
				$this->assign('result', $result);
				$this->display();	
			}
		}

		
	}
?>